﻿
using LxBasic;
using LxCore;

namespace LxCore.Samples
{
    public class LaminarNaturalConvection : SampleVMBase
    {
        public LaminarNaturalConvection() : base()
        {
            Name = "方腔自然对流";
            FileName= "Case2-Cavity.msh";
        }
        public override void RunCase()
        {
            ReadFile();
            //create physical model
            LxSim.Sim.Info.ProjName = Name;
            var physical = LxSim.Sim.Physics.CreatePhysicalModel();
            physical.PhysicalType = PhysicalTypes.流体;
            physical.SolveSetting.MomentumConvScheme = ConvectionSchemes.SecondOrder;
            physical.MaterialProperty.Density = new ConstField.Double(1.2);
            physical.MaterialProperty.Viscosity = new ConstField.Double(1e-5);
            physical.IsEnergyEnabled = true;
            physical.BuoyancyType = BuoyancyTypes.Boussinesq模型;
            //physical.IsGravityEnabled = true;
            physical.ReferenceValue.Gravity = new ConstField.Vector(new Vector3d(0, -9.8, 0));
            //3.设置边界条件
            var zone = FindZone("SOLID");
            ResHelper.GetCond(zone).PhysicalModel = physical;

            var thread_UP = FindBound(zone, "UP");
            ResHelper.GetCond(thread_UP).BoundType = BoundTypes.壁面;
            FvBound thread_DOWN = FindBound(zone, "DOWN");
            ResHelper.GetCond(thread_DOWN).BoundType = BoundTypes.壁面;
            FvBound thread_LEFT = FindBound(zone, "LEFT");
            ResHelper.GetCond(thread_LEFT).BoundType = BoundTypes.壁面;
            ResHelper.GetCond(thread_LEFT).WallThermalType = WallThermalTypes.定壁温;
            ResHelper.GetCond(thread_LEFT).Temperature = new ConstField.Double(310);
            FvBound thread_RIGHT = FindBound(zone, "RIGHT");
            ResHelper.GetCond(thread_RIGHT).BoundType = BoundTypes.壁面;
            ResHelper.GetCond(thread_RIGHT).WallThermalType = WallThermalTypes.定壁温;
            FvBound thread_FRONT = FindBound(zone, "FRONT");
            ResHelper.GetCond(thread_FRONT).BoundType = BoundTypes.对称面;
            FvBound thread_BACK = FindBound(zone, "BACK");
            ResHelper.GetCond(thread_BACK).BoundType = BoundTypes.对称面;
            //3.进行计算参数
            MultiThreads.SetThreadsCount(1);
            LxSim.Sim.Steps.IterationStep.MaxStepRule.MaxStep = 300;

            var graph = LxSim.Sim.Visuals.CreateGraph("流场");
            graph.GraphType = GraphTypes.矢量图;
            graph.ScalarType = ScalarFieldTypes.Velocity;
            graph.ScaleFactor = 0.2;
            graph.SetSelector(zone.Inner, true);
            graph = LxSim.Sim.Visuals.CreateGraph("温度场");
            graph.GraphType = GraphTypes.等值图;
            graph.ScalarType = ScalarFieldTypes.Temperature;
            graph.SetSelector(thread_UP, true);
            graph.SetSelector(thread_DOWN, true);
            graph.SetSelector(thread_LEFT, true);
            graph.SetSelector(thread_RIGHT, true);
            graph.SetSelector(thread_FRONT, true);
            graph.SetSelector(thread_BACK, true);
            //加载到界面
            RunSimulation();
        }
    }
}
